﻿@model CSCSN.ViewModels.RoleAndUser.ApplicationUserVM
@{
    ViewData["Title"] = "ForgetPassword";
}


<h1>忘记密码</h1>

<body>
    <div class="conales">
        @*<div class="imgBox">
                <img src="~/css/Img/4.jpg" />
            </div>*@
        <div class="RoleBox">

            <form action="/ApplicationUser/ForgetPassword" method="post" id="mis">
                <div asp-validation-summary="ModelOnly" class="text-danger"></div>


                <div class="input">
                    @*邮箱地址，它将作为用户账号使用 *@
                    <label asp-for="UserName" class="control-label"></label>
                    <input asp-for="UserName" class="form-control" id="Email" />
                    <span asp-validation-for="UserName" class="text-danger"></span>
                </div>


                <div class="input">


                    <label asp-for="Password" class="control-label"></label>
                    <input asp-for="Password" class="form-control" />
                    <span asp-validation-for="Password" class="text-danger"></span>
                </div>
                <div class="input">

                    <label asp-for="PasswordComfirm" class="control-label"></label>
                    <input asp-for="PasswordComfirm" class="form-control" />
                    <span asp-validation-for="PasswordComfirm" class="text-danger"></span>
                </div>

                <div class="input">
                    <label>验证码</label>
                    <input id="VerificationCodeInputField" name="Captcha" type="text" />
                    @*获取验证码按钮*@ <input type="button" value="获取验证码" id="VerificationCode" />
                </div>

                <div class="input">
                    <input type="submit" value="确认重置" class="btn btn-primary" id="Registration" onclick="registration()" />
                    @*<a asp-action="首页">返回首页</a>*@
                </div>
            </form>
        </div>
    </div>

</body>



@*以下为方法，不用动，*@
<script>

    var clock = '';
    var nums = 60;
    var btn;
    function doLoop() {
        nums--;
        if (nums > 0) {
            btn.value = '重新获取（' + nums + '）s';
        } else {
            clearInterval(clock); //清除js定时器
            btn.disabled = false;
            btn.value = '重新获取验证码';
            nums = 60; //重置时间
        }
    }

    var verificationCode = document.getElementById("VerificationCode");
    verificationCode.onclick = function () {


        var textdata = $341("#Email").val();
        console.log('hahah');
        console.log(textdata);

        if (textdata != null && textdata != "") {
            var flag = true;
            if (flag) {
                btn = this;
                btn.disabled = true; //将按钮置为不可点击
                btn.value = '重新获取（' + nums + '）s'
                clock = setInterval(doLoop, 1000)
            }

            $341.ajax({
                url: '/ApplicationUser/Mailbox',
                data: { EmailID: $341("#Email").val() },
                type: 'post',
                dataType: 'CorrectVerificationCodeJson',
                success: function (data) {
                    if (data != null) {
                        $341("#CorrectVerificationCode").val(data);
                    }
                }

            });
        }
        else {
            alert("请输入邮箱地址")
        }

    }




    //注册按钮单击后，校验验证码方法
    function registration() {
        $341.ajax({
            url: '/ApplicationUser/JudgeVerificat',
            data: { Verificat: $341("#VerificationCodeInputField").val() },
            async: true,
            type: 'post',
            dataType: 'Json',
            success: function (data) {
                console.log(data)
                if (data == "正确") {
                    var form = document.getElementById('mis');
                    form.submit();
                }
                if (data == "验证码为空") {
                    alert("请输入验证码！");
                }
                if (data == "错误") {

                    alert("验证码错误！");

                }
            }

        });
    }

</script>
